package com.etone.smartaudit.wopi.utils;

import sun.misc.BASE64Decoder;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;

/**
 * @author: sovy
 * @date: 2021/2/3
 * @description:
 */
public class Base64Util {
    private static BASE64Decoder base64Decoder;

    static {
        base64Decoder = new BASE64Decoder();
    }

    public static String decode(String str) {
        if (str == null) {
            return null;
        }
        try {
            byte[] bytes = base64Decoder.decodeBuffer(str);
            return new String(bytes);
        } catch (IOException ioException) {
            ioException.printStackTrace();
        }
        return null;
    }

    public static void main(String[] args) throws Exception {
        String url = "http%3A%2F%2Fdoc%2Ejiayen%2Ecn%2Fwopi%2Ffiles%2Fpath%2FNDU2LmRvY3g%3D%3Fpath%3DLzEvMTYyMDYzNTc1ODIwOV85Nzg5OS5kb2N4%26userName%3D5bCP5p6X5ZCM5a2m%26key%3D6cff22e57b3f2b14089dfd761b83881";
               url = "http%3A%2F%2Fdoc.jiayen.cn%2Fwopi%2Ffiles%2FLzIvMTYyMDY5ODQyNjc5NV84MjAxMy54bHN4%3FuserName%3DJUU1JUFFJTlDJUU5JTgwJTlBJUU4JUExJUExJUU3JTlEJUJG%26action%3Dedit%26ownerId%3Dadmin%26fileId%3D4%26abc%3D00a2t%26access_token%3D1d16aae371cc9ea5b8c788462c8f9490%26access_token_ttl%3D0";
        System.out.println(URLDecoder.decode(url,"utf-8"));
//        System.out.println(Base64Util.decode("LzdtZmQvYWJjZGVmZS5kb2N4"));
    }
}
